package fr.expdev.bndd;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import fr.expdev.bndd.data.Post;
import greendroid.app.GDActivity;
import greendroid.widget.ActionBarItem;
import greendroid.widget.NormalActionBarItem;

public class DetailPost extends GDActivity {

	private Post post;

	private WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setActionBarContentView(R.layout.detail_post);

		post = (Post)getIntent().getSerializableExtra("post");

		getActionBar().setTitle(post.getTitle());
		
		final ActionBarItem item = 
			getActionBar()
			.newActionBarItem(NormalActionBarItem.class)
        	.setDrawable(R.drawable.ab_book)
        	.setContentDescription(R.string.gd_export);
        addActionBarItem(item);

		webView = ((WebView) findViewById(R.id.detail_post_excerpt));

		webView.loadDataWithBaseURL("http://www.experience-developpement.fr/", post.getExcerpt(), "text/html", "utf-8", "about:blank");

	}

	/**
	 * Clic sur l'ActionBar
	 */
	@Override
	public boolean onHandleActionBarItemClick(ActionBarItem item, int position) {
		switch (position) {
			case 0 : 
				Intent intent = new Intent(this, WebPost.class);
				intent.putExtra("post", post);
				startActivity(intent);
				finish();
				break;
			default: return super.onHandleActionBarItemClick(item, position);
		}
		return true;
	}
	
}
